package com.laizhenghua.order.controller;

import com.laizhenghua.commons.entity.CommonResult;
import com.laizhenghua.commons.entity.PaymentEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @description:
 * @date: 2022/1/1 20:00
 */
@RestController
@RequestMapping(value = "/consumer")
public class OrderController {
    // public static final String PAYMENT_URL = "http://127.0.0.1:8001/payment";
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE/payment";

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/payment/create", method = RequestMethod.GET)
    public CommonResult<Integer> create(PaymentEntity entity) {
        CommonResult<Integer> result = restTemplate.postForObject(PAYMENT_URL + "/create", entity, CommonResult.class);
        return result;
    }

    @RequestMapping(value = "/payment/getPaymentById/{id}", method = RequestMethod.GET)
    public CommonResult<PaymentEntity> getPaymentById(@PathVariable(value = "id", required = true) Integer id) {
        return restTemplate.getForObject(PAYMENT_URL + "/getPaymentById/" + id, CommonResult.class);
    }
}
